package com.ftg.learn.framework.springframework.core.official.javabase;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.core.annotation.Order;

/**
 * 配置类 : javabase
 * - .class 表示 .xml
 * <p>
 * 组件不使用注解
 * 配置注解
 * configuration
 * bean
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/9/14 上午10:31
 */
@Configuration
@PropertySource("db.properties")
@ComponentScan("com.ftg.learn")
public class SpringConfiguration {


    @Value("${person.name}")
    private String name;

    /**
     * bean 把当前这个方法的返回値做为组件注入
     * id 为方法名称 默认
     *
     * bean id="initPear|bean" class="">
     *
     * @return
     */
    @Bean("pear")
    @Order(1)
    public Pear initPear() {
        Pear p = new Pear();
        p.setType("香水梨");
        return p;
    }

    @Bean("pear1")
    @Primary
    @Order(2)
    public Pear initPear1() {
        Pear p = new Pear();
        p.setType("香水梨1");
        return p;
    }

}
